﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;

namespace FlightSearchServer
{
    class LoggerBehavior : IEndpointBehavior
    {
        public LoggerBehavior() { }

        public LoggerBehavior(string fileName)
        {
            this.fileName = fileName;
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            foreach (DispatchOperation op in endpointDispatcher.DispatchRuntime.Operations)
            {
                if ( fileName == null || fileName.Length == 0)
                    op.ParameterInspectors.Add(new Logger());
                else
                    op.ParameterInspectors.Add(new Logger( fileName));
            }
        }

        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { }

        public void Validate(ServiceEndpoint endpoint) { }

        public string fileName { get; set; }
    }
}
